import { createRouter, createWebHashHistory } from 'vue-router'

import Home from '../pages/Home.vue'
import Login from '../pages/Login.vue'
import Error from '../pages/Error.vue'
import Index from '../pages/Home/Index.vue'
import Detection from '../pages/Home/big-screen/Detection.vue'
import GatAJob from '../pages/Home/big-screen/GatAJob.vue'
import Security from '../pages/Home/big-screen/Security.vue'
import Operation from '../pages/Home/big-screen/Operation.vue'
// import AA from '../pages/aa.vue'

const routes: any = [{
    path: '/',
    redirect: '/home'
}, {
    path: '/home',
    name: '后台管理系统',
    component: Home,
    children: [{
        path: '/home',
        redirect: '/home/index'
    }, {
        path: '/home/detection',
        name: '智能检测',
        // meta: {
        //     requireAuth: false
        // },
        component: Detection
    }, {
        path: '/home/gatajob',
        name: '就业态势',
        // meta: {
        //     requireAuth: false
        // },
        component: GatAJob
    }, {
        path: '/home/security',
        name: '安防管理',
        // meta: {
        //     requireAuth: false
        // },
        component: Security
    }, {
        path: '/home/index',
        name: '首页',
        // meta: {
        //     requireAuth: false
        // },
        component: Index
    }, {
        path: '/home/operation',
        name: '设备运维',
        // meta: {
        //     requireAuth: true
        // },
        component: Operation
    }]
}, {
    path: '/login',
    name: '后题管理登录',
    component: Login
}, {
    path: '/:pathMacth(.*)*',
    name: '404',
    component: Error
}];

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

router.beforeEach((to, form, next) => {
    if (to.path === '/login') {
        next()
    } else {
        if (window.localStorage.getItem('token')) {
            next()
        } else {
            next('/login')
        }
    }
})


export default router;